<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/6/29 0029
 * Time: 9:59
 */
namespace App\FreeBird\Controllers\Admin;
use App\Base\Controllers\Controller;
use App\FreeBird\Contracts\InfoClassInterface;
use Illuminate\Http\Request;


class InfoClassController extends Controller
{

    /**
     * @return InfoClassInterface
     */
    public function getInfoClassInterface(){
        return app()->make(InfoClassInterface::class);
    }

    /**
     * 新闻列表首页
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index(){

        $menuList=$this->getInfoClassInterface()->getClassAll([]);
        $menuArr=array();
        foreach ( $menuList as $k=> $item) {
            $menuArr[$k]["id"]=$item->id;
            $menuArr[$k]["name"]=$item->name;
            $menuArr[$k]["pId"]=$item->pid;
        }
        return view("freebird.infoclass.index")->with("menu_list",json_encode($menuArr));
    }

    /**
     * 获取用户信息
     * @param Request $request
     * @return mixed
     */
    public function edit(Request $request){

        return $this->getInfoClassInterface()->getInfo($request->all());
    }

    /**
     * 选择菜单
     * @param Request $request
     */
    public function classSelectMenus(Request $request){

        $menuList=$this->getInfoClassInterface()->getClassMenuList([]);
        $menuArr=array();
        foreach ( $menuList as $k=> $item) {
            $menuArr[$k]["id"]=$item->id;
            $menuArr[$k]["name"]=$item->name;
            $menuArr[$k]["pId"]=$item->pid;
        }
        return view("admin.config.show_select_menus")->with("menu_list",json_encode($menuArr));
    }

    public function del(Request $request){
        return $this->getInfoClassInterface()->delData($request->all());
    }

    /**
     * 保存数据
     * @param Request $request
     * @return mixed
     */
    public function save(Request $request){

        return   $this->getInfoClassInterface()->updateOrCreateClassClassData($request->all());
    }
    /**
     * 分类接口
     * @param $data
     */
    public function getInfoClassAll($data){
        return $this->getInfoInterface()->updateUserInfoApply($where, $data);
    }

}